<?php

namespace app\tenant\controller;

use think\Controller;
use Util\SysDb;
use think\Db;
class Orderlist extends Controller
{
    public function tenantlist()
    {
        $this->db = new SysDb();
        $data = $this->db->table('tenant_info')->lists();
        exit(json_encode(['message' =>'succ','result'=>$data]));
    }
    public function storelist()
    {
        $this->db = new SysDb();
        $data = $this->db->table('goods_store')->lists();
        exit(json_encode(['message' =>'succ','result'=>$data]));
    }
    public function orderlist()
    {
        $page = trim(input('param.pageNo'));
        $id = trim(input('param.tenantid'));
        $limit = trim(input('param.pageSize'));
        $status  = trim(input('param.status'));
        $busId  = trim(input('param.bus_id'));
        $storeId  = trim(input('param.store_id'));
        $orderId  = trim(input('param.id'));
        $where=array(
            "bus_id" => $busId,
            "status" => $status,
            "store_id" =>$storeId,
            "id" =>$orderId,
        );
        foreach ($where as $key=>$value)
        {
            if(empty($value)){
                unset($where[$key]);
            }
        }
        $tol = (intval($page) - 1) * $limit;
        $list = DB::name("order_info")->order("create_time desc")->where($where)->where(['tenant_id' => $id])->limit($tol, $limit)->select();
        $this->db = new SysDb();
        $count = $this->db->table('order_info')->where($where)->where(['tenant_id' => $id])->count();
        $data = array();
        array_push($data, $list);
        array_push($data, $count);
        exit(json_encode(['code' => 1, 'message' => 'succ', "result" => $data]));
    }
    public function goodlist()
    {
        
        $this->db = new SysDb();
        $data = $this->db->table('goods_info')->lists();
        exit(json_encode(['message' =>'succ','result'=>$data]));
    }
    public function orderlists()
    {
        $id = trim(input('param.tenantid'));
        $orderId=trim(input('param.orderId'));
        $page = trim(input('param.pageNo'));
        $limit = trim(input('param.pageSize'));
        $tol = (intval($page) - 1) * $limit;
        if($orderId==''){
            $list = DB::name("pk_info")->order("create_time desc")->where('tenant_id',  $id)->limit($tol, $limit)->select();
            $this->db = new SysDb();
            $count = $this->db->table('pk_info')->count();
            $data = array();
            array_push($data, $list);
            array_push($data, $count);
            exit(json_encode(['code' => 1, 'message' => 'succ', "result" => $data]));
        }else{
        $list = DB::name("pk_info")->order("create_time desc")->where('order_id',  $orderId)->where('tenant_id',  $id)->limit($tol, $limit)->select();
        $this->db = new SysDb();
        $count = $this->db->table('pk_info')->where(['order_id' => $orderId]) ->count();
        $data = array();
        array_push($data, $list);
        array_push($data, $count);
        exit(json_encode(['code' => 1, 'message' => 'succ', "result" => $data]));
    }
    }
}

